#include <iostream>
#define N 100

using namespace std;

int not_in_array(int array[], int size, int number){
int i,l=size, b=number;
for (i=0;i<l;i++)
    if(array[i]==b)
        return i;
return -1;
}

void asc_sort(int x[], int el){
int i, j, aux;
for(i=1; i<el; ++i){
    aux=x[i];
    j=i-1;
    while (aux<x[j] && j>=0){
        x[j+1]=x[j];
        --j;}
    x[j+1]=aux;}
}

void readVector_reunion(int reunion[], int el_union){
for (int i=0; i<el_union; i++){
	cout<<"a["<<i<<"]=";
	cin>>reunion[i];
	cout<<"\n";}
}

void readVector_intersection(int intersection[], int el_inter){
for (int i=0; i<el_inter;i++){
	cout<<"a["<<i<<"]=";
	cin>>intersection[i];
	cout<<"\n";}
}

void readVector_difference(int diff[], int el_diff){
for (int i=0; i<el_diff; i++){
	cout<<"a["<<i<<"]=";
	cin>>diff[i];
	cout<<"\n";}
}

int main(){
int el_union, el_diff, el_inter,i,j,k;
int array_a[N];
int array_b[N];
int diff[N];
int intersection[N];
int reunion[N];
int elements_a=0;
int elements_b=0;

cout<<"Number of elements in A U B: ";
cin>>el_union;
readVector_reunion(reunion, el_union);

cout<<"Number of elements in A ^ B (intersection): ";
cin>>el_inter;
readVector_intersection(intersection, el_inter);

cout<<"Number of elements in A \\ B: ";
cin>>el_diff;
readVector_difference(diff, el_diff);

for(i=0;i<el_inter;i++){
    array_a[i]=intersection[i];
    ++elements_a;
    array_b[i]=intersection[i];
    ++elements_b;}
for(i=0;i<el_diff;i++){
    array_a[elements_a]=diff[i];
    ++elements_a;}
for(j=0;j<el_union; j++)
    if(not_in_array(diff, el_diff, reunion[j])<0 && not_in_array(intersection, el_inter, reunion[j])<0){
        array_b[elements_b]=reunion[j];
        ++elements_b;}

asc_sort(array_a, elements_a);
asc_sort(array_b, elements_b);

cout<<"The original array A is ";
for(i=0; i<elements_a; i++){
	cout<<array_a[i]<<" ";}
cout<<endl;

cout<<"The original array B is ";
for(i=0; i<elements_b; i++){
	cout<<array_b[i]<<" ";}
cout<<endl;


return 0;
}
